import { createSlice } from "@reduxjs/toolkit";
import { getToken } from "../../utils/auth";

const userStore=createSlice({
    name:"user",
    initialState:{
        token:getToken(),
        user:{},
    },
    reducers:{
        setUser(state,action){
            state.user=action.payload;
        },
        setToken(state,action){
            state.token=action.payload;
        },
    },
});
//解构出刚才编写的两个方法
const { setToken, setUser } = userStore.actions;

//按需导出这两个方法
export { setToken, setUser };

//默认导出reducer
export default userStore.reducer;